//
//  HomeTransactPersonScrViewCollectionViewCell.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/15.
//

#import "HomeTransactPersonScrViewCollectionViewCell.h"
#import "HomeHeaderScrollCollectionViewCell.h"


@interface HomeTransactPersonScrViewCollectionViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong) UICollectionView * collectionView;
@property (nonatomic,strong) NSMutableArray * dataSource;
@property (nonatomic,strong) UIPageControl * pageControl;





@end


@implementation HomeTransactPersonScrViewCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.pageControl.currentPage = 0;
        self.pageControl.numberOfPages = 10;
        [self addSubview:self.collectionView];
        [self addSubview:self.pageControl];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.equalTo(self);
        }];
        
        
        [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.bottom.equalTo(self.collectionView.mas_bottom).with.offset(-ALIGN_HEIGHT_PT(20));
            make.height.equalTo(@(ALIGN_HEIGHT_PT(15)));
            make.width.equalTo(@(ALIGN_WIDTH_PT(200)));
        }];
       
        
        
        
    }
    return self;
}







#pragma mark -- UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//    return self.dataSource.count > 5 ? 5 : self.dataSource.count;
    return 10;
}

-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HomeHeaderScrollCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHeaderScrollCollectionViewCell" forIndexPath:indexPath];
//    [cell reloadImgShow:self.dataSource[indexPath.row]];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}



#pragma mark - item宽高
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(SCREEN_WIDTH, ALIGN_HEIGHT_PT(160));
}
/**
 这里我用代理设置以下间距 感兴趣可以自己调整值看看差别
 */
#pragma mark - <UICollectionViewDelegateFlowLayout>
#pragma mark - Y间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return  ALIGN_WIDTH_PT(0);
}
#pragma mark - X间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return ALIGN_WIDTH_PT(0);
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSInteger idx = scrollView.contentOffset.x/(SCREEN_WIDTH);
    self.pageControl.currentPage = idx;

}





#pragma mark -- 懒加载

-(UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;// 横向滚动
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.showsVerticalScrollIndicator = false;
        _collectionView.showsHorizontalScrollIndicator = false;
        _collectionView.pagingEnabled = YES;
        _collectionView.layer.cornerRadius = 10;
        _collectionView.layer.masksToBounds = YES;
        
        [_collectionView registerClass:[HomeHeaderScrollCollectionViewCell class] forCellWithReuseIdentifier:@"HomeHeaderScrollCollectionViewCell"];
        
    }
    
    return _collectionView;
}

- (UIPageControl *)pageControl{
    if(!_pageControl){
        _pageControl = [[UIPageControl alloc]init];
        _pageControl.pageIndicatorTintColor = COLOR_RGB(238, 238, 238);
        _pageControl.currentPageIndicatorTintColor = COLOR_RGB(245, 87, 80);
        
//        //监控用户用于pageController的点击事件
//        [_pageControl addTarget:self action:@selector(clickPageControl) forControlEvents:UIControlEventValueChanged];
    }
    return _pageControl;
}


@end
